package com.huike.web.controller.review;


import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.review.doamin.Review;
import com.huike.review.service.ReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 该Controller主要是为了复习三层架构以及Mybatis使用的，该部分接口已经放开权限，可以直接访问
 * 同学们在此处编写接口通过浏览器访问看是否能完成最简单的增删改查
 */
@RestController
@RequestMapping("/review")
public class MybatisReviewController extends BaseController {

    @Autowired
    private ReviewService reviewService;

    /**=========================================================新增数据============================================*/
    @GetMapping("/saveData/{name}/{age}/{sex}")
    public AjaxResult adds(@PathVariable String name,@PathVariable Integer age,@PathVariable String sex){
        return toAjax(reviewService.insertviews(name,age,sex));
    }

    @PostMapping("/saveData")
    public AjaxResult add(@RequestBody Review review){
        return toAjax(reviewService.insertview(review));
    }
    /**=========================================================删除数据=============================================*/
    @PostMapping("/update")
    public AjaxResult update(@RequestBody Review review){
        return toAjax(reviewService.updateview(review));
    }

    @DeleteMapping("/remove/{id}")
    public AjaxResult delete(@PathVariable Long id){
        return toAjax(reviewService.deleteview(id));
    }

    @GetMapping("/getById")
    public AjaxResult get( Long id){

        return AjaxResult.success(reviewService.getById(id));
    }

    @GetMapping("/getDataByPage")
    public TableDataInfo page(Review review, HttpServletRequest req) {
        startPage();
        List<Review> list = reviewService.selectReviewPool(review);
        return getDataTable(list);
        //return getDataTablePage(list);

    }


}